<?php

class CartsAction extends Action {
    public function index(){
    		if(empty($_SESSION['username'])){
    			header("Location:/dapu/index.php/Login/index");
    		}else{
    			$this->display();
    		}
    }
    
    public function getshopcar(){
    		$person['username'] = $_SESSION['username'];
    		$users = M("users");
    		$data = $users->where($person)->find();
    		$shopcar['userid'] = $data['id'];
    		$shopcart = M("shopcar");
    		$res = $shopcart->where($shopcar)->select();
    		if($res){
    			for($i = 0;$i<count($res);$i++){
	    			$goods = M("good");
	    			$good['id']=$res[$i]['goodid'];
	    			$goodinfo=$goods->where($good)->find();
		    		$goodinfo["imgurl"]=explode(',',$goodinfo["imgurl"])[0];
		    		$goodinfo["goodtype"] = $res[$i]['type'];
		    		$goodinfo["count"] = $res[$i]['count'];
	    			$info['goodinfo'][$i]=$goodinfo;
	    		}
    			$info['data']=$res;
    			$info['count']=$res[0]['goodid'];
    			$info['status']=1;
    		}else{
    			$info['data']="添加失败";
    			$info['status']=2;
    		}
    		$this->ajaxReturn($info);
    }
}

?>